/*
 * frmUser.java
 *
 * Created on April 29, 2010, 9:16 AM
 */
package GUI;

import Entity.User;
import Validate_Connect.CheckForm;
import Validate_Connect.DataInteraction;
import Validate_Connect.GUIInteraction;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author  Shinichi
 */
public class frmUser extends javax.swing.JInternalFrame {

    /** Creates new form frmUser */
    public frmUser() {
        initComponents();
        GUIInteraction.readToCombo("select * from tblRoles", _cboRole, "RoleName");
        refresh();
        _txtUserID.setEditable(false);
        _txtUsername.setEditable(false);
        _pwfPassword.setEditable(false);
        _pwfConfirmPass.setEditable(false);
        _txtAddress.setEditable(false);
        _txtBirthday.setEditable(false);
        _txtEmail.setEditable(false);
        _txtFullName.setEditable(false);
        _txtIdentityCard.setEditable(false);
        _btnreset.setEnabled(false);
        _btndelete.setEnabled(false);
        _btnupdate.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel5 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        _txtFullName = new javax.swing.JTextField();
        _txtAddress = new javax.swing.JTextField();
        _rdomale = new javax.swing.JRadioButton();
        _rdofemale = new javax.swing.JRadioButton();
        _txtBirthday = new javax.swing.JTextField();
        _txtIdentityCard = new javax.swing.JTextField();
        _txtEmail = new javax.swing.JTextField();
        _cboRole = new javax.swing.JComboBox();
        _cboStatus = new javax.swing.JComboBox();
        _lblerr = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        _txtUsername = new javax.swing.JTextField();
        _pwfPassword = new javax.swing.JPasswordField();
        _pwfConfirmPass = new javax.swing.JPasswordField();
        jLabel13 = new javax.swing.JLabel();
        _txtUserID = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        _btnaddNew = new javax.swing.JButton();
        _btnreset = new javax.swing.JButton();
        _btnupdate = new javax.swing.JButton();
        _btndelete = new javax.swing.JButton();
        _btnprint = new javax.swing.JButton();
        _btnclose = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        _tblUserList = new javax.swing.JTable(){
            public boolean isCellEditable(int rowIndex, int colIndex) {
                return false;   //Disallow the editing of any cell
            }
        };
        _tblUserList.getTableHeader().setReorderingAllowed(false);
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        _txtsearch = new javax.swing.JTextField();
        _cbochoice = new javax.swing.JComboBox();

        setClosable(true);
        setIconifiable(true);
        setTitle("AITSM - User");

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Information"));

        jLabel6.setText("Email:");

        jLabel4.setText("Address:");

        jLabel2.setText("FullName:");

        jLabel3.setText("Gender:");

        jLabel7.setText("Identity Card:");

        jLabel5.setText("Birthday:");

        jLabel11.setText("Role:");

        jLabel12.setText("Status:");

        _rdomale.setBackground(new java.awt.Color(255, 255, 255));
        buttonGroup1.add(_rdomale);
        _rdomale.setSelected(true);
        _rdomale.setText("Male");

        _rdofemale.setBackground(new java.awt.Color(255, 255, 255));
        buttonGroup1.add(_rdofemale);
        _rdofemale.setText("Female");

        _cboStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "True", "False" }));

        _lblerr.setFont(new java.awt.Font("Tahoma", 1, 11));
        _lblerr.setForeground(new java.awt.Color(255, 51, 0));

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel4)
                            .add(jLabel5)
                            .add(jLabel6))
                        .add(42, 42, 42)
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel3Layout.createSequentialGroup()
                                .add(_txtAddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 523, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 127, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jPanel3Layout.createSequentialGroup()
                                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jPanel3Layout.createSequentialGroup()
                                        .add(_txtBirthday, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 137, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(77, 77, 77)
                                        .add(jLabel7))
                                    .add(_txtEmail, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 265, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(22, 22, 22)
                                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(jPanel3Layout.createSequentialGroup()
                                        .add(jLabel12)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(_cboStatus, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .add(_txtIdentityCard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jPanel3Layout.createSequentialGroup()
                                        .add(52, 52, 52)
                                        .add(jLabel11)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(_cboRole, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 123, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(jPanel3Layout.createSequentialGroup()
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(_lblerr, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE))))))
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jLabel2)
                        .add(39, 39, 39)
                        .add(_txtFullName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 196, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(45, 45, 45)
                        .add(jLabel3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(_rdomale)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(_rdofemale)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(_rdofemale)
                    .add(_rdomale)
                    .add(jLabel3)
                    .add(_txtFullName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(_txtAddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel4))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(_txtBirthday, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel11)
                    .add(_txtIdentityCard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel7)
                    .add(_cboRole, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(_txtEmail, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel6)
                    .add(jLabel12)
                    .add(_cboStatus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(_lblerr))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Account", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel8.setText("Username:");

        jLabel9.setText("Password:");

        jLabel10.setText("Confirm Pass:");

        jLabel13.setText("UserID:");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(34, 34, 34)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel9)
                    .add(jLabel13))
                .add(40, 40, 40)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(_pwfPassword, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                        .add(58, 58, 58))
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(_txtUserID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(196, 196, 196)))
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel10)
                    .add(jLabel8))
                .add(33, 33, 33)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(_txtUsername, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                    .add(_pwfConfirmPass, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE))
                .add(29, 29, 29))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel13)
                    .add(_txtUserID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel8)
                    .add(_txtUsername, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel9)
                    .add(jLabel10)
                    .add(_pwfPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(_pwfConfirmPass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(75, 75, 75))
        );

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        _btnaddNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/list_add2.png"))); // NOI18N
        _btnaddNew.setText("Add New");
        _btnaddNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnaddNewActionPerformed(evt);
            }
        });

        _btnreset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/reset2.png"))); // NOI18N
        _btnreset.setText("Reset");
        _btnreset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnresetActionPerformed(evt);
            }
        });

        _btnupdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/update2.png"))); // NOI18N
        _btnupdate.setText("Update");
        _btnupdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnupdateActionPerformed(evt);
            }
        });

        _btndelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Delete2.png"))); // NOI18N
        _btndelete.setText("Delete");
        _btndelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btndeleteActionPerformed(evt);
            }
        });

        _btnprint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/printer2.png"))); // NOI18N
        _btnprint.setText("Print");
        _btnprint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnprintActionPerformed(evt);
            }
        });

        _btnclose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Logout16x16.png"))); // NOI18N
        _btnclose.setText("Close");
        _btnclose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btncloseActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(64, 64, 64)
                .add(_btnaddNew, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(_btnreset, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(_btnupdate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 97, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(_btndelete, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(_btnprint, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(_btnclose, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 91, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(75, 75, 75))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(_btnaddNew)
                .add(_btnclose)
                .add(_btnprint)
                .add(_btnreset)
                .add(_btnupdate)
                .add(_btndelete))
        );

        _tblUserList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        _tblUserList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                _tblUserListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(_tblUserList);

        jPanel1.setBackground(new java.awt.Color(0, 102, 102));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("User");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(374, Short.MAX_VALUE)
                .add(jLabel1)
                .add(355, 355, 355))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jLabel1)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel14.setText("Search:");

        _txtsearch.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                _txtsearchKeyReleased(evt);
            }
        });

        _cbochoice.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "By ID", "By Name", "By Address" }));

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel14)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(_txtsearch, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 582, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(_cbochoice, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 129, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .add(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .add(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .add(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel14)
                    .add(_cbochoice, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(_txtsearch, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 154, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 77, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void _btnaddNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnaddNewActionPerformed
    if (_btnaddNew.getText().equals("Add New")) {
        resetForm();
        _txtUserID.setEditable(true);
        _txtUsername.setEditable(true);
        _pwfPassword.setEditable(true);
        _pwfConfirmPass.setEditable(true);
        _txtAddress.setEditable(true);
        _txtBirthday.setEditable(true);
        _txtEmail.setEditable(true);
        _txtFullName.setEditable(true);
        _txtIdentityCard.setEditable(true);
        _btnaddNew.setText("Save");
        _txtUserID.requestFocus();
        _btndelete.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(false);
        _btnupdate.setEnabled(false);
        _btnclose.setEnabled(false);
    } else {
        if (!validateForm()) {
            return;
        }
        char[] _chrpass = _pwfPassword.getPassword();
        String _strPass = new String(_chrpass);

        String code = DataInteraction.getCodeString("tblRoles", "RoleName", _cboRole.getSelectedItem().toString(), "RoleID");
        Entity.User _user = new User();
        _user.set_UserID(_txtUserID.getText());
        _user.set_FullName(_txtFullName.getText());
        if (_rdomale.isSelected()) {
            _user.set_Gender(true);
        } else {
            _user.set_Gender(false);
        }
        _user.set_Address(_txtAddress.getText());
        _user.set_Birthday(_txtBirthday.getText());
        _user.set_Email(_txtEmail.getText());
        _user.set_IdentityCard(_txtIdentityCard.getText());
        _user.set_Username(_txtUsername.getText());
        _user.set_Password(_strPass);
        _user.set_RoleID(code);
        if (_cboStatus.getSelectedItem().toString().equals("True")) {
            _user.set_Status(true);
        } else {
            _user.set_Status(false);
        }
        Interact.Users.insertUser(_user);
        JOptionPane.showMessageDialog(null, "Insert succesfull", "Message", JOptionPane.INFORMATION_MESSAGE);
        _lblerr.setText("");
        refresh();
        resetForm();
        _txtUserID.setEditable(false);
        _txtUsername.setEditable(false);
        _pwfPassword.setEditable(false);
        _pwfConfirmPass.setEditable(false);
        _txtAddress.setEditable(false);
        _txtBirthday.setEditable(false);
        _txtEmail.setEditable(false);
        _txtFullName.setEditable(false);
        _txtIdentityCard.setEditable(false);
        _btndelete.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(true);
        _btnupdate.setEnabled(false);
        _btnclose.setEnabled(true);
        _btnaddNew.setText("Add New");
    }



}//GEN-LAST:event__btnaddNewActionPerformed

private void _btnresetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnresetActionPerformed
    resetForm();
    _btnreset.setEnabled(false);
    _btndelete.setEnabled(false);
    _btnupdate.setEnabled(false);
    }//GEN-LAST:event__btnresetActionPerformed

private void _btnupdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnupdateActionPerformed
    if (_btnupdate.getText().equals("Update")) {
        _txtUserID.setEditable(true);
        _txtUsername.setEditable(true);
        _pwfPassword.setEditable(true);
        _pwfConfirmPass.setEditable(true);
        _txtAddress.setEditable(true);
        _txtBirthday.setEditable(true);
        _txtEmail.setEditable(true);
        _txtFullName.setEditable(true);
        _txtIdentityCard.setEditable(true);
        _btnaddNew.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(false);
        _btndelete.setEnabled(false);
        _btnupdate.setText("Save");
        _txtUserID.requestFocus();
    } else {
        char[] _chrpass = _pwfPassword.getPassword();
        String _strPass = new String(_chrpass);

        String code = DataInteraction.getCodeString("tblRoles", "RoleName", _cboRole.getSelectedItem().toString(), "RoleID");
        Entity.User _user = new User();
        _user.set_UserID(_txtUserID.getText());
        _user.set_FullName(_txtFullName.getText());
        if (_rdomale.isSelected()) {
            _user.set_Gender(true);
        } else {
            _user.set_Gender(false);
        }
        _user.set_Address(_txtAddress.getText());
        _user.set_Birthday(_txtBirthday.getText());
        _user.set_Email(_txtEmail.getText());
        _user.set_IdentityCard(_txtIdentityCard.getText());
        _user.set_Username(_txtUsername.getText());
        _user.set_Password(_strPass);
        _user.set_RoleID(code);
        if (_cboStatus.getSelectedItem().toString().equals("True")) {
            _user.set_Status(true);
        } else {
            _user.set_Status(false);
        }
        Interact.Users.updateUser(_user);
        JOptionPane.showMessageDialog(null, "Update succesfull", "Message", JOptionPane.INFORMATION_MESSAGE);
        _lblerr.setText("");
        refresh();
        resetForm();
        _txtUserID.setEditable(false);
        _txtUsername.setEditable(false);
        _pwfPassword.setEditable(false);
        _pwfConfirmPass.setEditable(false);
        _txtAddress.setEditable(false);
        _txtBirthday.setEditable(false);
        _txtEmail.setEditable(false);
        _txtFullName.setEditable(false);
        _txtIdentityCard.setEditable(false);
        _btnaddNew.setEnabled(true);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(true);
        _btndelete.setEnabled(false);
        _btnupdate.setEnabled(false);
        _btnupdate.setText("Update");
    }

    }//GEN-LAST:event__btnupdateActionPerformed

private void _btndeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btndeleteActionPerformed
    String _id = _txtUserID.getText();
    int i = JOptionPane.showConfirmDialog(null, "Do you want delete Staff Name: " + _txtFullName.getText(), "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (i == 0) {
        Interact.Users.deleteUser(_id);
    }
    refresh();
    resetForm();
    _btnreset.setEnabled(false);
    _btndelete.setEnabled(false);
    _btnupdate.setEnabled(false);
    }//GEN-LAST:event__btndeleteActionPerformed

private void _btnprintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnprintActionPerformed
    ConnectDB.ConnectDB.runReport("src\\Report\\reportUserList.jasper");
    }//GEN-LAST:event__btnprintActionPerformed

private void _btncloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btncloseActionPerformed
    int i = JOptionPane.showConfirmDialog(null, "Do you want to exit?", "Exit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (i == 0) {
        this.dispose();
    }
}//GEN-LAST:event__btncloseActionPerformed

private void _tblUserListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event__tblUserListMouseClicked
    int i = _tblUserList.getSelectedRow();
    _txtUserID.setText(String.valueOf(_tblUserList.getValueAt(i, 0)));
    _pwfPassword.setText(String.valueOf(_tblUserList.getValueAt(i, 8)));
    _pwfConfirmPass.setText(String.valueOf(_tblUserList.getValueAt(i, 8)));
    _txtFullName.setText(String.valueOf(_tblUserList.getValueAt(i, 1)));
    Object _gender = _tblUserList.getValueAt(i, 2);
    if (_gender.equals("1")) {
        _rdomale.setSelected(true);
    } else {
        _rdofemale.setSelected(true);
    }
    _txtAddress.setText(String.valueOf(_tblUserList.getValueAt(i, 3)));
    _txtBirthday.setText(String.valueOf(_tblUserList.getValueAt(i, 4)));
    _txtEmail.setText(String.valueOf(_tblUserList.getValueAt(i, 5)));
    _txtIdentityCard.setText(String.valueOf(_tblUserList.getValueAt(i, 6)));
    _txtUsername.setText(String.valueOf(_tblUserList.getValueAt(i, 7)));
    _cboRole.setSelectedItem(_tblUserList.getValueAt(i, 9));

    _btnreset.setEnabled(true);
    _btndelete.setEnabled(true);
    _btnupdate.setEnabled(true);
    _btnprint.setEnabled(true);
    _btnclose.setEnabled(true);
    _txtUserID.setEditable(false);
    _txtUsername.setEditable(false);
    _pwfPassword.setEditable(false);
    _pwfConfirmPass.setEditable(false);
    _txtAddress.setEditable(false);
    _txtBirthday.setEditable(false);
    _txtEmail.setEditable(false);
    _txtFullName.setEditable(true);
    _txtIdentityCard.setEditable(false);
    if (_btnaddNew.getText().equals("Save")) {
        _btnaddNew.setText("Add New");
    }
    if (_btnupdate.getText().equals("Save")) {
        _btnupdate.setText("Update");
    }
    _btnaddNew.setEnabled(true);
}//GEN-LAST:event__tblUserListMouseClicked

private void _txtsearchKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event__txtsearchKeyReleased
    if (_cbochoice.getSelectedItem().equals("By ID")) {
        searchByID();
    } else if (_cbochoice.getSelectedItem().equals("By Name")) {
        searchByName();
    } else if (_cbochoice.getSelectedItem().equals("By Address")) {
        searchByAddress();
    }
}//GEN-LAST:event__txtsearchKeyReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _btnaddNew;
    private javax.swing.JButton _btnclose;
    private javax.swing.JButton _btndelete;
    private javax.swing.JButton _btnprint;
    private javax.swing.JButton _btnreset;
    private javax.swing.JButton _btnupdate;
    private javax.swing.JComboBox _cboRole;
    private javax.swing.JComboBox _cboStatus;
    private javax.swing.JComboBox _cbochoice;
    private javax.swing.JLabel _lblerr;
    private javax.swing.JPasswordField _pwfConfirmPass;
    private javax.swing.JPasswordField _pwfPassword;
    private javax.swing.JRadioButton _rdofemale;
    private javax.swing.JRadioButton _rdomale;
    private javax.swing.JTable _tblUserList;
    private javax.swing.JTextField _txtAddress;
    private javax.swing.JTextField _txtBirthday;
    private javax.swing.JTextField _txtEmail;
    private javax.swing.JTextField _txtFullName;
    private javax.swing.JTextField _txtIdentityCard;
    private javax.swing.JTextField _txtUserID;
    private javax.swing.JTextField _txtUsername;
    private javax.swing.JTextField _txtsearch;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    public boolean validateForm() {
        char[] _chrpass = _pwfPassword.getPassword();
        char[] _chrconfirmpass = _pwfConfirmPass.getPassword();
        String _strPass = new String(_chrpass);
        String _strConfirmPass = new String(_chrconfirmpass);

        if (!CheckForm.isEmpty(_txtUserID.getText())) {
            _lblerr.setText("Please enter UserID");
            _txtUserID.requestFocus();
            return false;
        }
        if (!CheckForm.isWhiteSpace(_txtUserID.getText())) {
            _lblerr.setText("UserID format is not validate");
            _txtUserID.requestFocus();
            return false;
        }
        if (!GUIInteraction.checkDuplicateID(_txtUserID.getText(), "select * from tblUser", "UserID")) {
            _lblerr.setText("UserID is duplication");
            _txtUserID.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtUsername.getText())) {
            _lblerr.setText("Please enter Username");
            _txtUsername.requestFocus();
            return false;
        }
        if (!CheckForm.isWhiteSpace(_txtUsername.getText())) {
            _lblerr.setText("Username is not validate");
            _txtUsername.requestFocus();
            return false;
        }
        if (!GUIInteraction.checkDuplicateID(_txtUsername.getText(), "select * from tblUser", "Username")) {
            _lblerr.setText("Username is duplication");
            _txtUsername.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_strPass)) {
            _lblerr.setText("Please enter Password");
            _pwfPassword.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_strConfirmPass)) {
            _lblerr.setText("Please enter Confirm Password");
            _pwfConfirmPass.requestFocus();
            return false;
        }
        if (!_strPass.equals(_strConfirmPass)) {
            _lblerr.setText("Pass and Confirm Pass must be the same");
            _pwfConfirmPass.requestFocus();
            return false;
        }

        if (!CheckForm.isEmpty(_txtFullName.getText())) {
            _lblerr.setText("Please enter FullName");
            _txtFullName.requestFocus();
            return false;
        }
        if (!_rdomale.isSelected() && !_rdofemale.isSelected()) {
            _lblerr.setText("You must choose gender.");
            return false;
        }
        if (!CheckForm.isEmpty(_txtAddress.getText())) {
            _lblerr.setText("Please enter Address");
            _txtAddress.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtBirthday.getText())) {
            _lblerr.setText("Please enter Birthday");
            _txtBirthday.requestFocus();
            return false;
        }
        if (!CheckForm.validateDate(_txtBirthday.getText())) {
            _lblerr.setText("Birthday format is not validate");
            _txtBirthday.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtEmail.getText())) {
            _lblerr.setText("Please enter Email");
            _txtEmail.requestFocus();
            return false;
        }
        if (!CheckForm.checkEmail(_txtEmail.getText())) {
            _lblerr.setText("Email is not validate");
            _txtEmail.requestFocus();
            return false;
        }

        return true;
    }

    public void resetForm() {
        _txtUserID.setText("");
        _txtUsername.setText("");
        _pwfPassword.setText("");
        _pwfConfirmPass.setText("");
        _txtFullName.setText("");
        _txtAddress.setText("");
        _txtBirthday.setText("");
        _txtIdentityCard.setText("");
        _txtEmail.setText("");
    }

    public void refresh() {
        try {
            GUIInteraction.readToTable("select u.UserID, u.FullName, u.Gender, u.Address, convert(char(10),u.Birthday,101), u.Email, u.IdentityCard, u. Username, u.Password, r.RoleName from tblUser u, tblRoles r where r.RoleID = u.RoleID", _tblUserList);
        } catch (SQLException ex) {
            Logger.getLogger(frmUser.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void searchByID() {
        String _str = _txtsearch.getText();
        String _sql = "";
        if (_str.equals("")) {
            _sql = "select u.UserID, u.FullName, u.Gender, u.Address, convert(char(10),u.Birthday,101), u.Email, u.IdentityCard, u. Username, u.Password, r.RoleName from tblUser u, tblRoles r where r.RoleID = u.RoleID";
        } else {
            _sql = "select u.UserID, u.FullName, u.Gender, u.Address, convert(char(10),u.Birthday,101), u.Email, u.IdentityCard, u. Username, u.Password, r.RoleName from tblUser u, tblRoles r where r.RoleID = u.RoleID and UserID like '%" + _str + "%'";
        }
        try {
            GUIInteraction.readToTable(_sql, _tblUserList);
        } catch (SQLException ex) {
            Logger.getLogger(frmStudent.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void searchByName() {
        String _str = _txtsearch.getText();
        String _sql = "";
        if (_str.equals("")) {
            _sql = "select u.UserID, u.FullName, u.Gender, u.Address, convert(char(10),u.Birthday,101), u.Email, u.IdentityCard, u. Username, u.Password, r.RoleName from tblUser u, tblRoles r where r.RoleID = u.RoleID";
        } else {
            _sql = "select u.UserID, u.FullName, u.Gender, u.Address, convert(char(10),u.Birthday,101), u.Email, u.IdentityCard, u. Username, u.Password, r.RoleName from tblUser u, tblRoles r where r.RoleID = u.RoleID and FullName like '%" + _str + "%'";
        }
        try {
            GUIInteraction.readToTable(_sql, _tblUserList);
        } catch (SQLException ex) {
            Logger.getLogger(frmStudent.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void searchByAddress() {
        String _str = _txtsearch.getText();
        String _sql = "";
        if (_str.equals("")) {
            _sql = "select u.UserID, u.FullName, u.Gender, u.Address, convert(char(10),u.Birthday,101), u.Email, u.IdentityCard, u. Username, u.Password, r.RoleName from tblUser u, tblRoles r where r.RoleID = u.RoleID";
        } else {
            _sql = "select u.UserID, u.FullName, u.Gender, u.Address, convert(char(10),u.Birthday,101), u.Email, u.IdentityCard, u. Username, u.Password, r.RoleName from tblUser u, tblRoles r where r.RoleID = u.RoleID and Address like '%" + _str + "%'";
        }
        try {
            GUIInteraction.readToTable(_sql, _tblUserList);
        } catch (SQLException ex) {
            Logger.getLogger(frmStudent.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
